const path = require('path')
const parse = require('./parser')
const loaderUtils = require('loader-utils')
const regexp = /(template\s*:\s*)null/;
const tag = '#abrazos-vue-designer';
const shortTag = '#avd';
module.exports = function (content) {
	//先检查短标记，再检查长标记，再检查是否有指定了template:null的，正则表达式比较慢，放在最后。建议写 #avd
	if(content.substring(0, shortTag.length) == shortTag || content.substring(0, tag.length) == tag || content.search(regexp) > -1){
		const isProduction = this.minimize || process.env.NODE_ENV === 'production'
	  
		const filePath = this.resourcePath
		const fileName = path.basename(filePath)
	  
		const context = (
		  this.rootContext ||
		  (this.options && this.options.context) ||
		  process.cwd()
		)
		const sourceRoot = path.dirname(path.relative(context, filePath))
		const parts = parse(
		  content,
		  fileName,
		  this.sourceMap,
		  sourceRoot,
		  false
		)
		var templateContent = '`' + parts.template.content + '`';
		return content.replace(regexp, "$1" + templateContent);
	}else{
		return content;
	}
}
